package com.leetcode.easy;

/**
 * @author zfl
 * @Classname TrailingZeroes
 * @Description
 * @Date 2020/10/6 14:30
 */
public class TrailingZeroes {
    /**
    * @param n
    * @return int
    * 阶乘容易超出int类型取值范围，故此题暴力法不行
    * 执行用时：6 ms, 在所有 Java 提交中击败了99.89%的用户
    * 内存消耗：36.2 MB, 在所有 Java 提交中击败了6.72%的用户
    */
    public static int trailingZeros(int n) {
        int zeroCount = 0;
        for (int i = 5; i <= n; i+= 5) {
            int currentFactor = i;
            while (currentFactor % 5 == 0) {
                zeroCount++;
                currentFactor /= 5;
            }
        }
        return zeroCount;
    }


}
